// MBStudioDoc.cpp : implementation of the CCodeDoc class
//

#include "../stdafx.h"
#include "../c/MBStudio.h"
#include "codeDoc.h"
#include "../../l_vmlib/Solution.h"
#include "../c/MainFrm.h"
#include "../resource.h"

extern CSolution theSln;

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

namespace EditCode{
/////////////////////////////////////////////////////////////////////////////
// CCodeDoc

IMPLEMENT_DYNCREATE(CCodeDoc, CDocument)

BEGIN_MESSAGE_MAP(CCodeDoc, CDocument)
	//{{AFX_MSG_MAP(CCodeDoc)
	ON_COMMAND(ID_READ_ONLY, OnReadOnly)
	ON_UPDATE_COMMAND_UI(ID_READ_ONLY, OnUpdateReadOnly)
	//}}AFX_MSG_MAP
	ON_COMMAND(ID_MARKUP_ADD, OnVmbAddcmt)
	ON_COMMAND(ID_MARKUP_REMOVE, OnVmbDelcmt)
	ON_COMMAND(ID_MARKUP_PROP, OnVmbEditdata)
	ON_COMMAND(ID_MARKUP_INFO, OnVmbGetinfo)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCodeDoc construction/destruction

#pragma warning(disable:4355)
CCodeDoc::CCodeDoc() : m_xTextBuffer(this)
{
	// TODO: add one-time construction code here

	//	Initialize LOGFONT structure
	memset(&m_lf, 0, sizeof(m_lf));
	m_lf.lfWeight = FW_NORMAL;
	m_lf.lfCharSet = ANSI_CHARSET;
	m_lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
	m_lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
	m_lf.lfQuality = DEFAULT_QUALITY;
	m_lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
	strcpy(m_lf.lfFaceName, "Courier");
	m_bMarkModify = 0;
}

CCodeDoc::~CCodeDoc()
{
}

BOOL CCodeDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	m_xTextBuffer.InitNew();
	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CCodeDoc serialization

void CCodeDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CCodeDoc diagnostics

#ifdef _DEBUG
void CCodeDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CCodeDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CCodeDoc commands

void CCodeDoc::DeleteContents() 
{
	CDocument::DeleteContents();

	m_xTextBuffer.FreeAll();
}

BOOL CCodeDoc::OnOpenDocument(LPCTSTR lpszPathName) 
{
	if (!CDocument::OnOpenDocument(lpszPathName))
		return FALSE;
	
	return m_xTextBuffer.LoadFromFile(lpszPathName);
}

BOOL CCodeDoc::OnSaveDocument(LPCTSTR lpszPathName) 
{
	m_xTextBuffer.SaveToFile(lpszPathName);
	return TRUE;	//	Note - we didn't call inherited member!
}

void CCodeDoc::OnReadOnly() 
{
	if (! m_xTextBuffer.GetReadOnly())
	{
		m_xTextBuffer.SetReadOnly(TRUE);
		AfxMessageBox("Document now read-only!");
	}
	else
		m_xTextBuffer.SetReadOnly(FALSE);
}

void CCodeDoc::OnUpdateReadOnly(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(m_xTextBuffer.GetReadOnly());
}

void CCodeDoc::OnVmbAddcmt()
{
	// TODO: Add your command handler code here
}

void CCodeDoc::OnVmbDelcmt()
{
	// TODO: Add your command handler code here
}

void CCodeDoc::OnVmbEditdata()
{
	// TODO: Add your command handler code here
}

void CCodeDoc::OnVmbGetinfo()
{
	// TODO: Add your command handler code here
}
};


